<?php
namespace app\admin\controller;
use \app\admin\controller\Server;
use think\Request;
use think\Image;
class Index extends \think\Controller {
	/**
     *当前接口:获取店铺内容信息及管理员
     */
	public function shopInfo() {
		$server = new Server();
		$server = $server->shopinfo();
		echo $server;
	}
	/**
     *当前接口:获取对应sku图书列表
     * 接收参数
     * suk 规格id
     */
	public function bookInfo() {
		$skuTap = input('skuTap');
		$sku = input('sku');
		$userid = input('userid');
		$type=input('type');
		$search = input('search');
		$server = new Server();
		$server = $server->shopList($skuTap,$sku,$userid,$search,$type);
		echo $server;
	}
	/**
     *当前接口:获取店铺图书分类id
     */
	public function bookSku() {
		$server = new Server();
		$server = $server->shopSku();
		echo $server;
	}
	/**
     *当前接口:获取用户openid 唯一标示
     */
	public function getUserId() {
		$code = input('code');
		$server = new Server();
		$server = $server->wx_login($code);
		echo $server;
	}
	/**
     *当前接口:根据openid获取用户值
     */
	public function userCentent() {
		$openid = input('openid');
		$nickname = input('nickname');
		$cover_img = input('cover_img');
		$create_time = input('create_time');
		$dateDay = input('dateDay');
		$server = new Server();
		$server = $server->userCentent($openid,$nickname,$cover_img,$create_time,$dateDay);
		echo $server;
	}
	/**
     *当前接口:
     *POST:请求：传入$shopNum,$shopId,$userId； // 商品数量，商品的id，用户id
     *GET请求：传入$userid   //用户ID
     */
	public function shopCart(Request $request) {
		if ($request->isPost()) {
			$shopNum = input('number');
			$shopId = input('shopid');
			$userId = input('userid');
			$server = new Server();
			$server = $server->shopcart($shopNum, $shopId, $userId);
			echo $server;
		}
		if ($request->isGet()) {
			$userid = input('userid');
			$server = new Server();
			$server = $server->shopCartList($userid);
			echo $server;
		}
	}
	/**
     *当前接口:首页分类商品触底刷新
     */
	public function onCodenum() {
		$pages = input('pages');
		$type = input('type');
		$skuTap = input('skuTap');
		$sku = input('sku');
		$search = input('search');
		$server = new Server();
		$server = $server->onCodenum($pages,$type, $sku,$skuTap,$search);
		echo $server;
	}
	/**
     *当前接口:订单详情
     */
	public function getOrderInfo() {
		$userid = input('userid');
		$server = new Server();
		$server = $server->getOrderInfo($userid);
		echo $server;
	}
	/**
     *当前接口:上传图片
     */
	public function postGoods() {
		$file = request()->file("category_img");
		$info = $file->move(ROOT_PATH.'public/static'.DS.'books_url');
		$list = ['books_url'=>'static/books_url/'.$info->getsaveName()];
		return json_encode($list,JSON_UNESCAPED_UNICODE);
	}
	/**
     *当前接口:添加分类
     */
	public function addTapSku(Request $request) {
		if ($request->isPost()) {
			$sukName = input('sukName');
			$type = input('type');
			$server = new Server();
			$server = $server->addTapSku($sukName,$type);
			echo $server;
		}
		if($request->isGet()) {
			$server = new Server();
			$server = $server->searchSku();
			echo $server;
		}
	}
	/**
     *当前接口:删除分类
     */
	public function delTapSku() {
		$skuid = input('skuid');
		$type = input('type');
		$server = new Server();
		$server = $server->delTapSku($skuid,$type);
		echo $server;
	}
	/**
     *当前接口:添加商品
     */
	public function addGoods() {
		$price = input('price');
		$bookname = input('bookname');
		$book_url = input('book_url');
		$sku = input('sku');
		$stock = input('stock');
		$type = input('type');
		$id = input('id');
		$second_sku = input('second_sku');
		$serial_number = input('serial_number');
		$server = new Server();
		$server = $server->addGoods($price,$bookname,$book_url,$sku,$stock,$type,$id,$second_sku,$serial_number);
		echo $server;
	}
	/**
     *当前接口:查询是否下过单有过地址
     */
	public function onUserAddress() {
		$userid = input('userid');
		$server = new Server();
		$server = $server->onUserAddress($userid);
		echo $server;
	}
	/**
     *当前接口:用户查看订单列表
     */
	public function getUserOrderInfoList() {
		$userid = input('userid');
		$orderType = input('orderType');
		$server = new Server();
		$server = $server->getUserOrderInfoList($userid,$orderType);
		echo $server;
	}
	/**
     *当前接口:删除购物车的商品
     */
	public function onGetCalierAll() {
		$userid = input('userid');
		$server = new Server();
		$server = $server->onGetCalierAll($userid);
		echo $server;
	}
	/**
     *当前接口:点击提交订单 // get 查看单个订单
     */
	public function onPlaceOrder(Request $request) {
		if ($request->isPost()) {
			$goodsList = input('goodsList');
			$userid = input('userid');
			$message = input('message');
			$userName = input('userName');
			$telNumber = input('telNumber');
			$provinceName = input('provinceName');
			$countyName = input('countyName');
			$detailInfo = input('detailInfo');
			$cityName = input('cityName');
			$count = input('count');
			$freight = input('freight');
			$pay_type = input('pay_type');
			$server = new Server();
			$server = $server->onPlaceOrder($userid,$message,$userName,$telNumber,$provinceName,$countyName,$detailInfo,$cityName,$goodsList,$count,$freight,$pay_type);
			echo $server;
		}
		if ($request->isGet()) {
			$orderId = input('orderId');
			$userid =  input('userid');
			$server = new Server();
			$server = $server->getUserOrderInfo($orderId,$userid);
			echo $server;
		}
	}
	/**
     *当前接口:获取单个商品的详情
     */
	public function onGoodsInfo() {
		$goodsid = input('goodsid');
		$server = new Server();
		$server = $server->onGoodsInfo($goodsid);
		echo $server;
	}
	/**
     *当前接口:获取用户列表
     */
	public function allUserlist() {
		$server = new Server();
		$server = $server->allUserlist();
		echo $server;
	}
	/**
     *当前接口:删除商品
     */
	public function onDeleteGoods() {
		$goodsid = input('goodsid');
		$server = new Server();
		$server = $server->onDeleteGoods($goodsid);
		echo $server;
	}
	/**
     *当前接口:商品上下架
     */
	public function onGoodsState() {
		$goodsid = input('goodsid');
		$status = input('status');
		$server = new Server();
		$server = $server->onGoodsState($goodsid,$status);
		echo $server;
	}
	/**
     *当前接口:店长订单状态修改
     */
	public function onOrderState() {
		$goodsid = input('orderId');
		$status = input('status');
		$code = input('code');
		$server = new Server();
		$server = $server->onOrderState($goodsid,$status,$code);
		echo $server;
	}
	/**
     *当前接口:用户收货状态修改
     */
	public function onOrderUserState() {
		$goodsid = input('orderId');
		$status = input('status');
		$server = new Server();
		$server = $server->onOrderUserState($goodsid,$status);
		echo $server;
	}
	/**
     *当前接口:店长查询所有订单
     */
	public function getOrder() {
		$server = new Server();
		$server = $server->getOrder();
		echo $server;
	}
	/**
     *当前接口:订单搜索
     */
	public function onOrderSearch() {
		$search = input('search');
		$userid = input('userid');
		$orderType = input('orderType');
		$server = new Server();
		$server = $server->onOrderSearch($search,$userid,$orderType);
		echo $server;
	}
	/**
     *当前接口:管理员设置
     */
	public function onAdminisaction() {
		$userid = input('upDataid');
		$type = input('type');
		$server = new Server();
		$server = $server->onAdminisaction($userid,$type);
		echo $server;
	}
	/**
     *当前接口:修改店铺信息
     */
	public function onUpdataShopInfo() {
		$shop_name = input('shop_name');
		$shop_phone = input('shop_phone');
		$shop_address = input('shop_address');
		$shop_url = input('shop_url');
		$lat = input('lat');
		$lon = input('lon');
		$freight = input('freight');
		$id=input('id');
		$server = new Server();
		$server = $server->onUpdataShopInfo($shop_name,$shop_phone,$shop_address,$shop_url,$lat,$lon,$id,$freight);
		echo $server;
	}
	/**
     *当前接口：版本号审核
     */
	public function send_template() {
		$getInfo = '1.0.1';
		return json_encode($getInfo,JSON_UNESCAPED_UNICODE);
	}
	/**
     *当前接口：取消订单
     */
	public function onLastOrder() {
		$userid = input('userid');
		$orderId = input('orderId');
		$reasons = input('reasons');
		$server = new Server();
		$server = $server->onLastOrder($userid,$orderId,$reasons);
		echo $server;
	}
	/**
     *当前接口：取消订单
     */
	public function upDateSku() {
		$sukName = input('sukName');
		$type = input('type');
		$server = new Server();
		$server = $server->upDateSku($sukName,$type);
		echo $server;
	}
	/**
     *当前接口：取消订单
     */
	public function Sku_second_sku() {
		$sukName = input('sukName');
		$type = input('type');
		$server = new Server();
		$server = $server->Sku_second_sku($sukName,$type);
		echo $server;
	}
	/**
     *当前接口：检查是否订单库存充足
     */
	public function userPayGoods() {
		$goodsList = input('goodsList');
		$server = new Server();
		$server = $server->userPayGoods($goodsList);
		echo $server;
	}
	public function onShippingReminder() {
		$openid = input('openid');
		$orderid = input('orderid');
		$goodName = input('goodName');
		$scanCode = input('scanCode');
		$data=date('y-m-d h:i:s',time());
		$server = new Server();
		$server = $server->onShippingReminder($openid,$orderid,$goodName,$scanCode,$data);
		echo $server;
	}
	public function onShippingRural(){
		$openid = input('openid');
		$orderid = input('orderid');
		$goodName = input('goodName');
		$data=date('y-m-d h:i:s',time());
		$server = new Server();
		$server = $server->onShippingRural($openid,$orderid,$goodName,$data);
		echo $server;
	}
	public function onCancelOrders(){
		$openid = input('openid');
		$orderid = input('orderid');
		$reasons = input('reasons');
		$server = new Server();
		$server = $server->onCancelOrders($openid,$orderid,$reasons);
		echo $server;
	}
	public function html(){
		return view('Index/index',[
      'name'=>'张老师',
      'lesson'=>'CSS',
      'domain'=>'www.php.cn'
    ]);
	}

	public function html2(){
		return 'ewew';
	}
}